#!/bin/bash



IP=${0##*/in_}

GUY=$(dig -t PTR +short $(echo ${IP} | awk -F "." '{for (i=NF;i>=1;i--) printf $i"."; print "in-addr.arpa."}') | awk -F '.' '{print $1}')

if [ "$1" = "config" ]; then

        echo "graph_order out in"
	title=${GUY}
	if [ -n "$hostname" ]; then
		title="$hostname"
	fi
        echo "graph_title $title traffic"
        echo 'graph_args --base 1000'
        echo 'graph_vlabel bits per second'
	echo 'graph_category lan'
        echo 'out.label sent'
        echo 'out.type DERIVE'
        echo 'out.min 0'
        echo 'in.label received'
        echo 'in.type DERIVE'
        echo 'in.min 0'
        exit 0
fi;

IP_UNDERSCORE=$(echo ${IP} | sed 's/\./_/g')
CHAIN_IN="acct_in_"${IP_UNDERSCORE}
CHAIN_OUT="acct_out_"${IP_UNDERSCORE}

/sbin/iptables -t filter -L ${CHAIN_IN}  -v -n -x | awk  '/ RETURN/{print "in.value "  $2*8;}'
/sbin/iptables -t filter -L ${CHAIN_OUT} -v -n -x | awk  '/ RETURN/{print "out.value " $2*8;}'

